package us.wili.dev.netty.jwt;

import us.wili.dev.jwt.model.IUser;

public class JwtUser implements IUser {

    public static final String USER_CERT_CATEGORY = "user.cert";
    public static final String USER_ID_KEY = "user.id";
    public static final String USER_PHONE_KEY = "user.phone";
    public static final String USER_NICKNAME_KEY = "user.nickname";
    public static final String USER_HEADIMGURL_KEY = "user.headimgurl";

    public static final String WX_OPENID_KEY = "wechat.openid";
    public static final String WX_NICKNAME_KEY = "wechat.nickname";
    public static final String WX_UNIONID_KEY = "wechat.unionid";
    public static final String WX_HEADIMGURL_KEY = "wechat.headimgurl";

    private Long userId;
    private Integer certificationCategory;
    private String phone;
    private String nickname;
    private String headimgurl;
    private String wxOpenid;
    private String wxNickname;
    private String wxUnionid;
    private String wxHeadimgurl;

    private Boolean isAnonymous = true;
    private String uuid;
    private Integer channel;

    private long expiredSeconds;


    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Integer getCertificationCategory() {
        return certificationCategory;
    }

    public void setCertificationCategory(Integer certificationCategory) {
        this.certificationCategory = certificationCategory;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getHeadimgurl() {
        return headimgurl;
    }

    public void setHeadimgurl(String headimgurl) {
        this.headimgurl = headimgurl;
    }

    public String getWxOpenid() {
        return wxOpenid;
    }

    public void setWxOpenid(String wxOpenid) {
        this.wxOpenid = wxOpenid;
    }

    public String getWxNickname() {
        return wxNickname;
    }

    public void setWxNickname(String wxNickname) {
        this.wxNickname = wxNickname;
    }

    public String getWxUnionid() {
        return wxUnionid;
    }

    public void setWxUnionid(String wxUnionid) {
        this.wxUnionid = wxUnionid;
    }

    public String getWxHeadimgurl() {
        return wxHeadimgurl;
    }

    public void setWxHeadimgurl(String wxHeadimgurl) {
        this.wxHeadimgurl = wxHeadimgurl;
    }

    @Override
    public Boolean getAnonymous() {
        return isAnonymous;
    }

    public void setAnonymous(Boolean anonymous) {
        isAnonymous = anonymous == null ? true : anonymous;
    }

    @Override
    public String getId() {
        return this.isAnonymous ? "uuid:" + this.uuid : String.format("%d:%d", this.channel, this.getUserId());
    }

    @Override
    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    @Override
    public Integer getChannel() {
        return channel;
    }

    public void setChannel(Integer channel) {
        this.channel = channel;
    }

    @Override
    public String getSubject() {
        return nickname;
    }

    @Override
    public long getExpiredSeconds() {
        return expiredSeconds;
    }

    public void setExpiredSeconds(long expiredSeconds) {
        this.expiredSeconds = expiredSeconds;
    }
}